<%-- 
    Document   : attendance
    Created on : 2019-7-18, 15:59:45
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/color.css" type="text/css" />
        <link rel="stylesheet" href="../../css/demo.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>        
        <script language="JavaScript">
            
            $(document).ready(function() {
                $('#tabs').tabs({
                    border: false,
                    onSelect: function(title) {
                        // get the selected tab panel and its tab object
                        var pp = $('#tabs').tabs('getSelected');
                        var selectedTab = pp.panel('options').tab;    // the corresponding tab object
                        var content = selectedTab.content;
                        //alert(content);
                        //alert(title);
                        if("考勤管理"==title)
                            $('#dg').datagrid('reload');    // reload the user data
                    },
                    onBeforeClose:function(title,index){
                        var rows = $('#dg-detail').datagrid('getChanges');
                        var target = this;
                        if(rows==undefined||rows==null||rows==""){ //没有变化，可以关闭窗口
                            return true;
                        }else{
                            $.messager.confirm('提示','记录已更改，还没有保存！确定要关闭此标签吗？',function(r){ 
                                if (r){
                                    var opts = $(target).tabs('options');
                                    var bc = opts.onBeforeClose;
                                    opts.onBeforeClose = function(){};  // allowed to close now
                                    $(target).tabs('close',index);
                                    opts.onBeforeClose = bc;  // restore the event function
                                }
                            });
                            return false;	// prevent from closing
                        }
                        
                        
                  }
                });
                $('#dg').datagrid('getPanel').panel('setTitle',courseName);
                $('#dg').datagrid('fitColumns');
                /*alert(courseName);
                alert($('#mainPanle').width() - 10);
                $('#dg').datagrid({
                    width: 300,
                    height: 250,
                })*/
            });
            
        </script>
    </head>
    <body>
        <div id="tabs" class="easyui-tabs" fit="true" border="false">
            <div title="考勤管理" style="padding: 5px; overflow: hidden;" id="attendance">
                <table id="dg" title="${courseName}" class="easyui-datagrid"
                       url="../../servlet/teacher/GetAttendances"
                       toolbar="#toolbar" striped="true" 
                       rownumbers="true" fitColumns="true" singleSelect="true">
                    <thead>
                        <tr>
                            <th field="ID"  hidden="true" width="50">ID</th>
                            <th field="no" width="30">序号</th>                            
                            <th field="createTime" width="120">考勤时间</th>
                            <th field="status" width="50">考勤</th>
                            <th field="note" width="150">备注</th>                            
                        </tr>
                    </thead>
                </table>
                <div id="toolbar">
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newAttendance()">增加</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editAttendance()">修改</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyAttendance()">删除</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="refreshAttendance()">刷新</a>
                    <!--<a href="#" class="easyui-linkbutton" iconCls="icon-large_chart" plain="true" onclick="showAll()">考勤表</a>-->
                </div>
            </div>
        </div>
        <script >
            //alert(parent.teachclassid);
            var courseName = '<%=session.getAttribute("courseName")%>';
            var attendanceId  = -1;
            function newAttendance(){
                var dd = $('#dg').datagrid('getData');                
                addTab('考勤明细', encodeURI('attendancedetail.jsp?no='+(dd.total+1)+'&attendanceId=-1'));                
            }
            function showAll(){
                addTab('考勤表', encodeURI('attendanceTable.jsp'));
            }
            function editAttendance(){
                var row = $('#dg').datagrid('getSelected');
                if (row) {      
                   //alert(attendanceId+" "+row.no);
                   addTab('考勤明细', encodeURI('attendancedetail.jsp?no='+(row.no)+'&attendanceId='+row.ID));
                }else{
                     $.messager.alert({
                                title: '提示',
                                msg: '请选择一条记录进行修改',
                                icon:'info'
                            });
                }
            }
            function destroyAttendance(){
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('提示', '您确定要删除该次考勤吗?', function(r) {
                        if (r) {
                            $.post('../../servlet/teacher/DestroyAttendance', {id: row.ID}, function(result) {
                                if (result.success) {
                                    $('#dg').datagrid('reload');    // reload the user data
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
            function refreshAttendance(){
                $('#dg').datagrid('reload');    // reload the user data
            }
            function addTab(subtitle, url) {
                    if (!$('#tabs').tabs('exists', subtitle)) {
                        var content = '<iframe name="mainFrame" scrolling="auto" frameborder="0" src="' + url + '" style="width:100%;height:100%;"></iframe>';
                        $('#tabs').tabs('add', {
                            title: subtitle,
                            href: url,
                            //content:content,
                            closable: true,
                            width: $('#mainPanle').width() - 10,
                            height: $('#mainPanle').height() - 26,
                            cache: true
                        });
                    } else {
                        $('#tabs').tabs('select', subtitle);
                    }
                    tabClose();
                }
                 function createFrame(url) {
                    var s = '<iframe name="mainFrame" scrolling="auto" frameborder="0" src="' + url + '" style="width:100%;height:100%;"></iframe>';
                    return s;
                }
                function tabClose() {
                    /*双击关闭TAB选项卡*/
                    $(".tabs-inner").dblclick(function() {
                        var subtitle = $(this).children("span").text();
                        $('#tabs').tabs('close', subtitle);
                    })
                    $(".tabs-inner").bind('contextmenu', function(e) {
                        $('#mm').menu('show', {
                            left: e.pageX,
                            top: e.pageY,
                        });
                        var subtitle = $(this).children("span").text();
                        $('#mm').data("currtab", subtitle);
                        return false;
                    });
                }
//绑定右键菜单事件
                function tabCloseEven() {
//关闭当前
                    $('#mm-tabclose').click(function() {
                        var currtab_title = $('#mm').data("currtab");
                        $('#tabs').tabs('close', currtab_title);
                    })
//全部关闭
                    $('#mm-tabcloseall').click(function() {
                        $('.tabs-inner span').each(function(i, n) {
                            var t = $(n).text();
                            $('#tabs').tabs('close', t);
                        });
                    });
//关闭除当前之外的TAB
                    $('#mm-tabcloseother').click(function() {
                        var currtab_title = $('#mm').data("currtab");
                        $('.tabs-inner span').each(function(i, n) {
                            var t = $(n).text();
                            if (t != currtab_title)
                                $('#tabs').tabs('close', t);
                        });
                    });
//关闭当前右侧的TAB
                    $('#mm-tabcloseright').click(function() {
                        var nextall = $('.tabs-selected').nextAll();
                        if (nextall.length == 0) {
//msgShow('系统提示','后边没有啦~~','error');
                            alert('后边没有啦~~');
                            return false;
                        }
                        nextall.each(function(i, n) {
                            var t = $('a:eq(0) span', $(n)).text();
                            $('#tabs').tabs('close', t);
                        });
                        return false;
                    });
//关闭当前左侧的TAB
                    $('#mm-tabcloseleft').click(function() {
                        var prevall = $('.tabs-selected').prevAll();
                        if (prevall.length == 0) {
                            alert('到头了，前边没有啦~~');
                            return false;
                        }
                        prevall.each(function(i, n) {
                            var t = $('a:eq(0) span', $(n)).text();
                            $('#tabs').tabs('close', t);
                        });
                        return false;
                    });
//退出
                    $("#mm-exit").click(function() {
                        $('#mm').menu('hide');
                    })
                }
        </script>
    </body>
</html>
